package junior.Simulation模拟;

public class minPath {
    public static void main(String[] args) {
        int[][] a1 = {
                {0,1,1,2,2},
                {0,1,2,2,1}};
        int[][] a = {
                {0,0},
                {1,1},
                {1,2},
                {2,2},
                {2,1}};
        int minPath = path(a,5);
    }
    static int path(int[][] a,int n){
        double[][] temp= new double[n+1][n+1];

        int x,y;
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                x = Math.abs(a[j][0] - a[i][0]);
                y = Math.abs(a[j][1] - a[i][1]);
                temp[i][j] = Math.sqrt(x*x + y*y);
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < i; j++) {
                temp[i][j] = temp[j][i];
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.printf("%.2f\t",temp[i][j]);
            }
            System.out.println();
            System.out.println();
        }
        double[] path = new double[n]; // 第一行存储最值，第二行标记：0：未标记，1：标记
        int[] check = new int[n];
        int[] order = new int[n];
        double temMax = 100000;
        int ind = 0,j =0;
        for (int i = 0; i < n; i++) {
            for (; j < n;) {
                if(temp[i][j] < temMax && check[j] == 0){ // 遍历最最小值，未被标记
                // 更新下标
                    ind = j;
                // 更新最值
                    temMax = temp[i][j];
                }
            }
            check[ind] = 1;
            path[i] = temMax;
            order[i] = ind;
            j = ind;

        }


        return 0;
    }
}
